package com.newsmanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newsmanagement.domain.pojo.SlauBatch;
import com.newsmanagement.mapper.SlauBatchMapper;
import com.newsmanagement.service.SlauBatchService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author adim
 * @description 针对表【slau_batch(屠宰企业产品批号信息表)】的数据库操作Service实现
 * @createDate 2025-10-11 15:17:30
 */
@Service
public class SlauBatchServiceImpl extends ServiceImpl<SlauBatchMapper, SlauBatch>
        implements SlauBatchService {

    /**
     * 根据屠宰企业ID查询产品批号列表
     * 仅查询状态有效（非下架）的批号，符合实际业务中“批发商仅能选择有效批号”的逻辑
     */
    @Override
    public List<SlauBatch> getBySlauId(Integer slauId) {
        LambdaQueryWrapper<SlauBatch> queryWrapper = new LambdaQueryWrapper<>();
        // 核心条件1：匹配传入的屠宰企业ID
        queryWrapper.eq(SlauBatch::getSlauId, slauId)
                // 核心条件2：过滤已下架状态（state=3），仅保留有效批号（1-新建、2-待确认、3-已确认，根据需求文档定义）
                .ne(SlauBatch::getState, 3)
                // 按批号录入日期倒序，让最新批号排在前面，提升用户体验
                .orderByDesc(SlauBatch::getBatchDate);

        return baseMapper.selectList(queryWrapper);
    }
}




